﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTD2013.Common;

namespace DTD2013.DTDLib
{
    public class DTDStack<T>
    {
        public int Count { get { return ObjectList.Count; } }

        private List<T> ObjectList = new List<T>();

        public void Push(T item)
        {
            if (ObjectList.Count == Constant.STACK_LENGTH)
            {
                ObjectList.RemoveAt(0);
            }
            ObjectList.Add(item);
        }

        public T Pop()
        {
            if (ObjectList.Count > 0)
            {
                T result = ObjectList[ObjectList.Count - 1];
                ObjectList.RemoveAt(ObjectList.Count - 1);
                return result;
            }
            return default(T);
        }        
    }
}
